package com.gaojunxiang.service;

import com.gaojunxiang.dao.UserDao;
import com.gaojunxiang.domain.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
     @Autowired
     private UserDao userDao;
    public boolean save(User user) {
        return userDao.save(user);
    }

    public boolean delete(Integer id) {
        return userDao.delete(id);
    }

    public boolean update(User user) {
        return userDao.update(user);
    }

    public User findById(Integer id) {
      //  return userDao.findById(id);
     //   System.out.println(userDao.findById(id));
        return userDao.findById(id);
    }

    public User login(String username, String password) {
        return userDao.findByUsernameAndPassword(username,password);
    }

    public PageInfo<User> findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> all = userDao.findAll();
        PageInfo<User> userPageInfo = new PageInfo<>(all);
        return userPageInfo;
    }
}
